﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
namespace DAO
{
    public class DAO_LoaiPhong
    {
        #region 1. Inserting
        public static bool ThemLoaiPhong(DTO_LoaiPhong lp)
        {
            bool result = false;
            try
            {
                string sql;
                sql = @"INSERT INTO db_LoaiPhong VALUES  ('" + lp.MaLoaiPhong + "','" + lp.TenLoaiPhong + "','" + lp.DonGia + "')";
                RunQuery.RunNonQuery(sql);
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region 2. Delete
        public static bool XoaLoaiPhong(DTO_LoaiPhong lp)
        {
            bool result = false;
            try
            {
                string sql;
                sql = @"DELETE FROM db_LoaiPhong WHERE MaLoaiPhong = '" + lp.MaLoaiPhong + @"'";
                RunQuery.RunNonQuery(sql);
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
        #region 4. Retrieving

        public static List<DTO_LoaiPhong> LayTatCaLoaiPhong()
        {
            List<DTO_LoaiPhong> llp = new List<DTO_LoaiPhong>();
            try
            {
                string sql;
                sql = @"SELECT * FROM db_LoaiPhong";
                SqlDataAdapter a = new SqlDataAdapter();
                a = RunQuery.RunQueryData(sql);
                DataTable dt = new DataTable();
                a.Fill(dt);
                foreach (DataRow dr in dt.Rows)
                {
                    DTO_LoaiPhong lp = new DTO_LoaiPhong();
                    lp.MaLoaiPhong = dr[0].ToString();
                    lp.TenLoaiPhong = dr[1].ToString();
                    string DonGia = dr[2].ToString();
                    lp.DonGia = Double.Parse(DonGia);

                    llp.Add(lp);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return llp;
        }
        #endregion
    }
}
